import { ISummer, lcuSummonerInfo } from "../interface/SummonerInfo.ts";
import { invoke } from "@tauri-apps/api";
import { RankStatus } from "../interface/RankInfo.ts";

/**
 * 查询召唤师信息接口
 */

//查询当前召唤师头像,name,经验
export const queryCurrentSummoner = async (): Promise<ISummer> => {
  return getSumInfo(await invoke("get_cur_sum"));
};
//根据接口返回过滤所需参数
export const getSumInfo = (summonerInfo: lcuSummonerInfo): ISummer => {
  const imgUrl = `https://wegame.gtimg.com/g.26-r.c2d3c/helper/lol/assis/images/resources/usericon/${summonerInfo.profileIconId}.png`;
  return {
    name: summonerInfo.displayName,
    imgUrl,
    lv: summonerInfo.summonerLevel,
    xpSL: summonerInfo.xpSinceLastLevel,
    xpNL: summonerInfo.xpUntilNextLevel,
    puuid: summonerInfo.puuid,
    currentId: summonerInfo.summonerId,
  };
};
/**
 * 根据puuid查询rank信息
 * @param puuid
 */
export const getRankPoint = async (puuid: string) => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const rankPoint: any = await invoke("get_cur_rank_point", { puuid: puuid });
  let rankInfo: RankStatus[] = [];
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const { RANKED_SOLO_5x5, RANKED_FLEX_SR, RANKED_TFT } = rankPoint.queueMap;
  const RankSolo = new RankStatus("单人/双人", RANKED_SOLO_5x5);
  const RankFlex = new RankStatus("灵活5V5", RANKED_FLEX_SR);
  const RankTft = new RankStatus("云顶之弈", RANKED_TFT);
  rankInfo = [RankSolo, RankFlex, RankTft];
  return rankInfo;
};
